package com.atguigu.boot.config;

import com.atguigu.boot.interceptors.MyInterceptors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 把当前类标记为一个配置类
@Configuration
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    private MyInterceptors myInterceptors;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // ant 风格地址匹配模式：/*表示匹配请求路径中的一级
        // ant 风格地址匹配模式：/**表示匹配请求路径中的多级
        // /apple/aaa
        // /apple/aaa/bbb
        registry.addInterceptor(myInterceptors).addPathPatterns("/apple/**");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //    @GetMapping("/friend")
        //    public String friend() {
        //        return "target";
        //    }
        registry.addViewController("/friend").setViewName("target");
    }
}
